package com.itheima.Interceptor;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
//  喜爱你在这个注解就是将它放入Spring里面去
public class DemoInterceptor implements HandlerInterceptor {
    //首先Interceptor需要继承HandlerInterceptor---实现三个方法


    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("前置逻辑，在目标方法前执行");
        //放行就是true 拒绝就是false
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println("后置逻辑，在目标方法后执行");
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        System.out.println("后置逻辑，在目标方法后执行，如果有（多个拦截器的posthandle）的PostHandle目标方法执行完后，再去执行这个方法");
    }
}
